<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: fzh<fanzhaohai@hrbjjhh.com>
// +----------------------------------------------------------------------------

namespace Admin\Model;
use Admin\Model\BaseModel;
/**
 * 客户信息模型
 */
class ServiceCustomerDetailModel extends BaseModel {

    /* 自动验证规则 */
    protected $_validate = array(
        array('customer_name', '1,5', '姓名的长度不能超过5个字符', self::VALUE_VALIDATE, 'length', self::MODEL_UPDATE),
        array('sex', array(0,1,2), '性别输入错误', self::VALUE_VALIDATE, 'in', self::MODEL_UPDATE),
        array('qq', 'number', 'QQ号码必须为数字', self::VALUE_VALIDATE, '', self::MODEL_UPDATE),
        array('qq', '1,12', 'QQ长度不能超过12个数字', self::VALUE_VALIDATE, 'length', self::MODEL_UPDATE),
        array('wechat', '1,15', '微信长度不能超过15个字符', self::VALUE_VALIDATE, 'length', self::MODEL_UPDATE),
        array('mailbox', 'email', '邮箱格式不正确', self::VALUE_VALIDATE, '', self::MODEL_UPDATE),
        array('mailbox', '1,30', '邮箱长度不能超过30个字符', self::VALUE_VALIDATE, 'length', self::MODEL_UPDATE),
        array('phone_number', '1,20', '手机号码长度不能超过20个字符', self::VALUE_VALIDATE, 'length', self::MODEL_UPDATE),
        array('remark', '1,2000', '备注不能超过2000个字符', self::VALUE_VALIDATE, 'length', self::MODEL_UPDATE),
    );

    /* 自动完成规则 */
    protected $_auto = array(
//         array('customer_name', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
//         array('is_valid', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
//         array('sex', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
//         array('qq', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
//         array('wechat', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
//         array('mailbox', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
//         array('phone_number', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
//         array('remark', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
    );

    public function update(){
        /* 获取数据对象 */
        $data = $this->create($_POST);
        if(empty($data)){
            $this->error =$this->getError();
            return false;
        }
        if(false === $this->add($data,array(),true)){
            $this->error = $this->getDbError();
            return false;
        }else{
            return true;
        }
    }
    /**
     * @todo 返回主键
     * @see \Think\Model::getPk()
     */
    public function getPk(){
        return 'customer_id';
    }
}